<script setup>
import { ref,onMounted } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()

// 用户资料
const user = ref({
  avatar: '/avatar.jpg', // 默认头像
  username: '用户123',
  email: 'user@example.com'
})

// 任务统计
const stats = ref({
  completed: 15,
  inProgress: 8,
  streak: 3
})

// 通知设置
const notificationsEnabled = ref(true)

// 主题模式
const theme = ref(localStorage.getItem('theme') || 'light')

// 切换主题
const toggleTheme = () => {
  theme.value = theme.value === 'light' ? 'dark' : 'light'
  document.documentElement.setAttribute('data-theme', theme.value)
  localStorage.setItem('theme', theme.value) // 持久化存储
}

// 初始化主题
onMounted(() => {
  document.documentElement.setAttribute('data-theme', theme.value)
})
</script>

<template>
  <div class="user-profile-page">
    <h2 class="page-title">个人中心</h2>

    <!-- 用户资料卡片 -->
    <div class="profile-card">
      <div class="profile-header">
        <img :src="user.avatar" alt="头像" class="avatar" />
        <div class="profile-info">
          <input 
            v-model="user.username" 
            class="input" 
            placeholder="用户名" 
          />
          <input 
            v-model="user.email" 
            class="input" 
            placeholder="邮箱" 
          />
        </div>
      </div>
    </div>

    <!-- 任务统计卡片 -->
    <div class="stats-card">
      <h3 class="section-title">任务统计</h3>
      <div class="stats-grid">
        <div class="stat-item">
          <p class="stat-number">{{ stats.completed }}</p>
          <p class="stat-label">已完成任务</p>
        </div>
        <div class="stat-item">
          <p class="stat-number">{{ stats.inProgress }}</p>
          <p class="stat-label">进行中任务</p>
        </div>
        <div class="stat-item">
          <p class="stat-number">{{ stats.streak }}</p>
          <p class="stat-label">连续打卡</p>
        </div>
      </div>
    </div>

    <!-- 设置卡片 -->
    <div class="settings-card">
      <h3 class="section-title">设置</h3>
      <div class="setting-item">
        <label class="setting-label">
          <span>接收任务提醒</span>
          <input 
            type="checkbox" 
            v-model="notificationsEnabled" 
            class="checkbox" 
          />
        </label>
      </div>
      
      <div class="setting-item theme-toggle">
        <span>主题模式</span>
        <button 
          @click="toggleTheme" 
          class="theme-btn"
        >
          {{ theme === 'light' ? '🌙 切换为深色' : '☀️ 切换为浅色' }}
        </button>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
/* 全局主题变量 */
:root {
  --primary: #3b82f6;
  --white: #ffffff;
  --black: #1a1a1a;
  --gray-100: #f5f7fa;
  --gray-200: #d1d5db;
  --gray-300: #9ca3af;
  --gray-400: #6b7280;
  --success: #22c55e;
  --error: #dc2626;
}

/* 深色主题变量 */
[data-theme="dark"] {
  --background: #1a1a1a;
  --foreground: #ffffff;
  --card-bg: #2d2d2d;
  --border-color: #444444;
}

/* 浅色主题变量（默认） */
[data-theme="light"] {
  --background: #ffffff;
  --foreground: #1a1a1a;
  --card-bg: #ffffff;
  --border-color: #d1d5db;
}

.user-profile-page {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem;
  min-height: 100vh;
  background-color: var(--background);
  color: var(--foreground);
  font-family: 'Segoe UI', sans-serif;
}

.page-title {
  font-size: 2.25rem;
  font-weight: 700;
  margin-bottom: 2rem;
  color: var(--primary);
}

/* 用户资料卡片 */
.profile-card {
  background-color: var(--card-bg);
  border-radius: 1rem;
  padding: 2rem;
  margin-bottom: 2rem;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  border: 1px solid var(--border-color);
}

.profile-header {
  display: flex;
  align-items: center;
  gap: 2rem;
}

.avatar {
  width: 8rem;
  height: 8rem;
  border-radius: 50%;
  border: 4px solid var(--primary);
  object-fit: cover;
}

.profile-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.input {
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  background-color: transparent;
  color: var(--foreground);
  transition: border-color 0.3s ease;
}

.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* 任务统计卡片 */
.stats-card {
  background-color: var(--card-bg);
  border-radius: 1rem;
  padding: 2rem;
  margin-bottom: 2rem;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  border: 1px solid var(--border-color);
}

.section-title {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
  color: var(--primary);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 2rem;
}

.stat-item {
  text-align: center;
  padding: 1.5rem;
  background-color: rgba(59, 130, 246, 0.1);
  border-radius: 0.75rem;
}

.stat-number {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  font-size: 0.875rem;
  color: var(--gray-400);
}

/* 设置卡片 */
.settings-card {
  background-color: var(--card-bg);
  border-radius: 1rem;
  padding: 2rem;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  border: 1px solid var(--border-color);
}

.setting-item {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.setting-item:last-child {
  border-bottom: none;
}

.setting-label {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 1rem;
  color: var(--foreground);
}

.checkbox {
  width: 1.5rem;
  height: 1.5rem;
  accent-color: var(--primary);
}

.theme-btn {
  padding: 0.5rem 1.5rem;
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
  background-color: var(--primary);
  color: var(--white);
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.theme-btn:hover {
  opacity: 0.9;
}
</style>